#include <iostream>
#include <vector>
#include <cstdio>
#include <unistd.h>
#include "thread.hpp"
using namespace ThreadMoudle;

const int gnum = 10;
void Print(const std::string &name)
{
    int cnt = 1;
    while (true)
    {
        std::cout<<name<<"is running,cnt: "<<cnt++<<std::endl;
        sleep(1);
    }
}
int main()
{
    std::vector<Thread> threads;
    for (int i = 0; i < gnum; i++)
    {
        std::string name = "thread-" + std::to_string(i + 1);
        threads.emplace_back(name, Print); // 每次在threads容器里尾部构造一个Thread对象
        sleep(1);
    }
    // 统一启动
    for (auto &thread : threads)
    {
        thread.start();
    }
    sleep(10);
    // 统一结束
    for (auto &thread : threads)
    {
        thread.stop();
    }
    // 等待线程等待
    for (auto &thread : threads)
    {
        thread.join();
    }

    Thread s("thread-1",Print);     //对线程1单独测试，测试各时候的状态
    s.start();
    std::cout << s.Name() << ", status: " << s.status() << std::endl;
    sleep(10);
    std::cout << s.Name() << ", status: " << s.status() << std::endl;
    s.stop();
    sleep(1);
    std::cout << s.Name() << ", status: " << s.status() << std::endl;
    s.join();
    std::cout << "join done" <<std::endl;
    return 0;
}